/**
 * 2
 *  
 * @Author : roryrywang
 * @DateTime : 24-8-29 下午3:53
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int res = 0;

bool check(vector<int> &tmp) {
    for (int i = 1; i < tmp.size(); ++i) {
        if (max(tmp[i], tmp[i - 1]) % min(tmp[i], tmp[i - 1]) != 0) return false;
    }
    return true;
}

void dfs(vector<int> &a, vector<int> &tmp, vector<bool> &st, int k) {
    if (k == a.size()) {
        if (check(tmp)) res++;
        return;
    }
    for (int i = 0; i < a.size(); ++i) {
        if (!st[i]) {
            st[i] = true;
            tmp.push_back(a[i]);
            dfs(a, tmp, st, k + 1);
            st[i] = false;
            tmp.pop_back();
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<bool> st(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        st[i] = false;
    }
    vector<int> tmp;
    dfs(a, tmp, st, 0);
    cout << res;
    return 0;
}